<?php

namespace App\Services;


use App\Enums\IsValidEnum;
use App\Enums\ProjectCompanyTypeEnum;
use App\Enums\ProjectStatusEnum;
use App\Enums\SelectorTypesEnum;
use App\Models\AdminUsers;
use App\Models\Contract\ContractTemplateModel;
use App\Models\ProjectCompanys\ProjectCompanysModel;
use App\Models\Projects\ProjectsModel;
use App\Services\Master\Payment\PaymentChannelsService;
use App\Util\LoginUtil;
use File;
use Str;

class GlobalService extends BaseService
{
    /**
     * Reference数据
     */
    public function reference()
    {
        $enums = \File::allFiles(app_path('Enums'));

        $rs = $this->autoEnums($enums);

        return $rs;
    }

    public function autoEnums($files)
    {
        $skip_dirs = ['\\Private'];
        $rs = [];
        if (!empty($files)) {
            foreach ($files as $file) {
                // 获取类型、命名空间
                $name = Str::replace('.php', '', File::name($file));
                $dir = File::dirname($file);
                $dir = str_ireplace(app_path('Enums'), "", $dir);
                $dir = str_ireplace(DIRECTORY_SEPARATOR, "\\", $dir);
                if (in_array($dir, $skip_dirs)) {
                    continue;
                }
                $class = "App\\Enums" . rtrim($dir, '\\') . "\\" . $name;

                // 调用类方法
                $array = call_user_func([$class, 'asArray']);
                $key = Str::camel($name);
                $rs[$key] = collect($array)->map(function ($item, $key) use ($class) {
                    return ['label' => call_user_func([$class, 'getDescription'], $item), 'value' => is_int($item) ? (int)$item : $item, 'key' => $key];
                })->values()->toArray();
            }
        }
        return $rs;
    }


}
